<?php
set_time_limit ( 0 );
include_once '../connect.php';

//环境变量
//////排序
$head_sort = '<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Untitled Document</title>
		<link rel="stylesheet" href="../table/themes/blue/style.css" type="text/css" id="" media="print, projection, screen" />
		<script type="text/javascript" src="../table/jquery-latest.js"></script>
		<script type="text/javascript" src="../table/jquery.tablesorter.js"></script>
		<script type="text/javascript">
		$(function() {
			$("table").tablesorter({debug: false});
		});
		</script>
	</head>
	<body>
	<table id="rowspan" cellspacing="0" class="tablesorter">';

$table_head = '<thead>
				<tr>
				<th>序号</th>
					
					<th>区县</th>
					<th>社区名</th>	
					<th>竣工时间</th>	
					<th>售楼均价（元/平米）</th>	
					<th>租售比</th>	
					<th>年化收益率</th>	
				</tr>
			</thead>
			';
//////////////////////////////////////////////////////////////////////北京租售比
$city = array ("beijing", "tianjin", "shanghai", "shenzhen", "chengdu", "hangzhou", "guangzhou", "chongqing", "dalian", "suzhou", "foshan", "wuhan", "sjz", "nanjing", "cs", "zhengzhou",  "wuxi", "xa", "jinan", "qd", "ks" );

foreach ( $city as $c ) {
	$insert = '';
	$file_name = '../biaoge/' . $c . '.htm';
	
	$insert = $head_sort . $table_head;
	
	$sql = "select * from fangjia where url like '%" . $c . "%' and zushoubi <> 0 and zushoubi is not null ";
	$result = mysql_query ( $sql, $dbc ) or die ( mysql_error () );
	$n = 0;
	while ( $arr = mysql_fetch_array ( $result ) ) {
		++ $n;
		$insert .= "<tr>
	<td>$n</td>
					
					<td>$arr[qu]</td>
					<td>$arr[xiaoqu]</td>	
					<td>$arr[jungongriqi]</td>
					<td>$arr[shoujia]</td>	
					<td>$arr[zushoubi]</td>		
					<td>$arr[nianshouyi]</td>		
				</tr>
				";
	}
	$insert .= '	</tbody>
</table>
	</body>
</html>';
	$handle = fopen ( "$file_name", "w" );
	if (fwrite ( $handle, $insert ) === FALSE) {
		echo "不能写入到文件 $filename";
		exit ();
	}
	echo $c . "租售比写完了<br>";
	fclose ( $handle );
}

?>